<?php
/*
 * Created on 2009-7-19
 *
 * Author: guobin@yizin.net
 */
global $header;
global $footer;
global $menu;

global $serial;
global $privilege;
global $privilegeJson;
global $error;

global $featureManager;
$header['title'] = '编辑权限 - 用户管理';
$header['head'] = '
<script type="text/javascript">
var privilege='.$privilegeJson.';
function changed1(obj)
{
	var id = obj.id;
	id = id.substring("privilege.".length);
	var items = privilege["items"][id]["items"];
	for(var i in items)
	{
		document.getElementById("privilege."+id+"."+i).checked = obj.checked;
	}
}

function changed2(obj)
{
	var id = obj.id;
	var parentId = id.substring("privilege.".length);
	parentId = parentId.substring(0, parentId.indexOf("."));
	var items = privilege["items"][parentId]["items"];
	var allChecked = true;
	for(var i in items)
	{
		allChecked &= document.getElementById("privilege."+parentId+"."+i).checked;
	}
	document.getElementById("privilege."+parentId).checked=allChecked;
}
</script>
<style type="text/css">
ul.sub {margin-left:20px;}
</style>
';
$featureManager->apply("com.yizin.platform.admin.header", $header);
$menu['current'] = 'user.role';
$featureManager->apply("com.yizin.platform.admin.menu", $menu);
$featureManager->apply("com.yizin.platform.admin.footer", $footer);
?>
<?= $header['html'] ?>
<div class="ysi-container-C">
    <div class="ysi-container-CI">
        <div>
            <a href="<?=REQUEST_BASE?>admin/user/role/">&lt;&lt;返回角色管理</a>
        </div>
        <form id="privilege-form" action="<?=REQUEST_BASE?>admin/user/role/<?=$serial?>/privilege/" method="post">
            <div>
                <?php
                foreach ($privilege['items'] as $key1=>$item1)
                {
                ?>
                <strong><input id="privilege.<?=$key1?>" name="privilege.<?=$key1?>" type="checkbox" onchange="changed1(this);" <?=$item1['allow']?'checked="checked"':''?> />
                    <label for="privilege.<?=$key1?>">
                        <?= $item1['text'] ?>
                    </label>
                </strong>
                <ul class="sub">
                    <?php
                    foreach ($item1['items'] as $key2=>$item2)
                    {
                    ?>
                    <li>
                        <input id="privilege.<?=$key1?>.<?=$key2?>" name="privilege.<?=$key1?>.<?=$key2?>" type="checkbox" onchange="changed2(this);" <?=$item2['allow']?'checked="checked"':''?> />
                        <label for="privilege.<?=$key1?>.<?=$key2?>">
                            <?= $item2['text'] ?>
                        </label>
                    </li>
                    <?php
                    }
                    ?>
                </ul>
                <?php
                }
                ?>
                <strong><input id="privilege.default" name="privilege.default" type="checkbox" <?=$privilege['default']?'checked="checked"':''?> />
                    <label for="privilege.default">
                        默认具有权限
                    </label>
                </strong>
            </div>
            <div>
                <input type="submit" value="提交" />
            </div>
        </form>
    </div>
</div>
<div class="ysi-container-L">
    <?= $menu['html'] ?>
</div>
<?= $footer['html'] ?>
